<extend name="Common/layout" />

<block name="title"><title>关于我们</title></block>

<block name='css'>

</block>

<block name="content">

    <!--content-->
    <div class="col-sm-offset-2">

        <div class="panel panel-default">
            <div class="panel-body" style="height:70px;">
                <div class="form-group">
                    <div class="col-sm-3">
                        <p style="font-size: 25px">关于我们</p>
                    </div>
                    <div class="col-sm-1 col-sm-offset-7">
                        <button class="btn btn-primary" onclick="fetchData()">重置</button>
                    </div>
                </div>
            </div>
        </div>
        <div class="panel panel-default" style="min-height: 500px">
            <div class="panel-body" style="margin: 20px;">

                <script type="text/plain" id="myEditor" name="content"></script>

            </div>
        </div>
        <div>
            <div class="pull-right">
                <button class="btn btn-warning" onclick="saveOur()">保存</button>
                <button class="btn btn-primary" onclick="fetchData()">重置</button>
            </div>
        </div>
        <div style="height: 200px">

        </div>
    </div>
</block>

<block name="js">
    <script type="text/javascript" src="__PUBLIC__/js/ueditor/ueditor.config.js"></script>
    <script type="text/javascript" src="__PUBLIC__/js/ueditor/ueditor.all.js"></script>
    <script type="text/javascript">
        var editor = new baidu.editor.ui.Editor({initialFrameHeight:400});
        editor.render("myEditor");
        editor.setOpt('autoHeight',false);

        editor.addListener("ready", function () {

            editor.setContent('{:isset($text)?$text:""}');

        });

        function saveOur(){
            $.ajax({
               url: "{:U('Our/saveOur')}",
                type:"POST",
                dataType:'json',
                data:{
                    'text': editor.getContent()
                },
                success: function(json){
                    if(json == 'success'){
                        alert('保存成功');
                    }else{
                        alert('保存失败');
                    }
                }
            });
        }
        var fetchData = function(){
            $.ajax({
                url: "{:U('Our/getOur')}" ,
                dataType:'json',
                success:function(json){
                    editor.setContent(json);
                }
            });
        }

    </script>

</block>